/*
 * @Author: jiu yin
 * @Date: 2023-05-15 14:50:04
 * @LastEditTime: 2023-08-16 17:57:20
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \AI admin\src\redux\modules\asyncRouter.ts
 * jiu
 */
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import type { PayloadAction } from "@reduxjs/toolkit";
import type { routeArrItem } from "@/type/index.ts";

// 异步
export const getRouter = createAsyncThunk("getRouter", async (value: any) => {
  // 模拟一个异步操作，延迟 2 秒钟返回数据
  return new Promise((resolve) => {
   setTimeout(() => {
     resolve(value);
   }, 2000);
 });
});

export const asyncRouter = createSlice({
   name: "asyncRouter",
   initialState: { routerStr: '[]' as string},
   reducers: {

   },
   //异步
   extraReducers: builder => {
      builder.addCase(getRouter.fulfilled, (state, action) => {
         //@ts-ignore
         state.routerStr = action.payload; // 返回值
      });
   },
});

// Action creators are generated for each case reducer function


export default asyncRouter.reducer;
